﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LamSon.Controllers
{
    public class RuongMuoiNhaController : BaseController
    {
        //
        // GET: /RuongMuoiNha/
        BaseController bs = new BaseController();
        public ActionResult RuongMuoiNha()
        {
            return bs.BaseIndex(9, "RuongMuoiNha");
        }

        public static List<Data.DBOES.RuongMuoiNha> getListRuongMuoiNha(string ruongmuoi,string nguoilam,string noinhap)
        {
            Data.DBOES.RuongMuoiNha objCon = new Data.DBOES.RuongMuoiNha();
           
            if (string.IsNullOrEmpty(ruongmuoi))
            {
                objCon.RuongMuoi = null;
            }
            else
            {
                objCon.RuongMuoi =HttpUtility.HtmlEncode(Commons.Commons.RemoveHtmlTag(ruongmuoi)) ;
            }
            if (string.IsNullOrEmpty(nguoilam))
            {
                objCon.NguoiLam = null;
            }
            else
            {
                objCon.NguoiLam = HttpUtility.HtmlEncode(Commons.Commons.RemoveHtmlTag(nguoilam));
            }
            if (string.IsNullOrEmpty(noinhap))
            {
                objCon.NoiNhap = null;
            }
            else
            {
                objCon.NoiNhap = HttpUtility.HtmlEncode(Commons.Commons.RemoveHtmlTag(noinhap));
            }
            objCon.SortBy = "NgayThang";
            objCon.SortType = Core.SortType.DESC;
            List<Data.DBOES.RuongMuoiNha> objList = Data.Controllers.RuongMuoiNhaController.FindItems(objCon, BaseController.Pagecurr, BaseController.LimitPage, ref BaseController.totalRow);
            return objList;
        }
        public ActionResult Delete(string idRuongMuoiNha)
        {
            Data.DBOES.RuongMuoiNha objCon = Data.Controllers.RuongMuoiNhaController.FindItem(new Data.DBOES.RuongMuoiNha(Commons.DataTypeProtect.ProtectInt32(idRuongMuoiNha)));
            if (objCon != null)
                objCon.Delete();
            ReturnViewData_RuongMuoiNha(null,null,null);
            return PartialView("ListRuongMuoiNha");
        }
        public ActionResult Edit(string idRuongMuoiNha_Edit, string ruongmuoi_sendedit,string nguoilam_sendedit,string noinhap_sendedit, string pagesize_sendedit, string page_sendedit)
        {
            Data.DBOES.RuongMuoiNha objCon = Data.Controllers.RuongMuoiNhaController.FindItem(new Data.DBOES.RuongMuoiNha(Commons.DataTypeProtect.ProtectInt32(idRuongMuoiNha_Edit)));
            ViewData["DataRuongMuoiNha"] = objCon;
            SetViewDataInfoSearch(ruongmuoi_sendedit,nguoilam_sendedit,noinhap_sendedit, pagesize_sendedit, page_sendedit);
            return PartialView("FormRuongMuoiNha");

        }
        public ActionResult OK(string idRuongMuoiNha_OK)
        {
            Data.DBOES.RuongMuoiNha objCon = Data.Controllers.RuongMuoiNhaController.FindItem(new Data.DBOES.RuongMuoiNha(Commons.DataTypeProtect.ProtectInt32(idRuongMuoiNha_OK)));
            if (objCon != null)
            {
                objCon.IsActive = true;
                objCon.Update();
            }
            ReturnViewData_RuongMuoiNha(null,null,null);
            return PartialView("ListRuongMuoiNha");
        }
        //
        // GET: /NhatKyBanHang/Create
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Update(string IdRuongMuoiNha,DateTime? NgayThang,string RuongMuoi,string NguoiLam,string SoXe,float? SoLuong,float? DonGia,float? AnChia,string NoiNhap,string DienGiai,string GhiChu,bool? IsActive,
            string ruongmuoi_edit,string nguoilam_edit,string noinhap_edit, string pagesize_edit, string page_edit
            )
        {
            Data.DBOES.RuongMuoiNha objCon;
            if (!string.IsNullOrEmpty(IdRuongMuoiNha))
            {
                objCon = Data.Controllers.RuongMuoiNhaController.FindItem(new Data.DBOES.RuongMuoiNha(Commons.DataTypeProtect.ProtectInt32(IdRuongMuoiNha)));
            }
            else
            {
                objCon = new Data.DBOES.RuongMuoiNha();
            }
            
            BaseController.LimitPage = Commons.DataTypeProtect.ProtectInt32(string.IsNullOrEmpty(pagesize_edit) ? "50" : pagesize_edit);
            BaseController.Pagecurr = Commons.DataTypeProtect.ProtectInt32(string.IsNullOrEmpty(page_edit) ? "1" : page_edit);
            ReturnViewData_RuongMuoiNha(ruongmuoi_edit, nguoilam_edit, noinhap_edit);
            return PartialView("ListRuongMuoiNha");
        }
        public void SetViewDataInfoSearch(string ruongmuoi_sendedit,string nguoilam_sendedit,string noinhap_sendedit, string pagesize_sendedit, string page_sendedit)
        {
            ViewData["ruongmuoi_sendedit"] = ruongmuoi_sendedit;
            ViewData["nguoilam_sendedit"] = nguoilam_sendedit;
            ViewData["noinhap_sendedit"] = noinhap_sendedit;
            ViewData["pagesize_sendedit"] = pagesize_sendedit;
            ViewData["page_sendedit"] = page_sendedit;
        }
        public ActionResult LoadPage(string page, string ruongmuoi_paging,string nguoilam_paging,string noinhap_paging)
        {
            BaseController.Pagecurr = LamSon.Commons.DataTypeProtect.ProtectInt32(page);
            ReturnViewData_RuongMuoiNha(ruongmuoi_paging,nguoilam_paging,noinhap_paging);
            return PartialView("ListRuongMuoiNha");
        }
        public ActionResult LoadLimitPage(string pagesize, string ruongmuoi_limit,string nguoilam_limit,string noinhap_limit)
        {
            BaseController.LimitPage = LamSon.Commons.DataTypeProtect.ProtectInt32(pagesize);
            BaseController.Pagecurr = 1;
            ReturnViewData_RuongMuoiNha(ruongmuoi_limit, nguoilam_limit, noinhap_limit);
            return PartialView("ListRuongMuoiNha");
        }
        public ActionResult LoadPageSearch(string ruongmuoi,string nguoilam,string noinhap)
        {
            BaseController.Pagecurr = 1;
            ReturnViewData_RuongMuoiNha(ruongmuoi, nguoilam, noinhap);
            return PartialView("ListRuongMuoiNha");
        }
        public ActionResult LoadPaging()
        {
            if (totalRow % LimitPage == 0)
            {
                ViewData["TotalPage"] = totalRow / LimitPage;
            }
            else
            {
                ViewData["TotalPage"] = totalRow / LimitPage + 1;
            }
            ViewData["PageCurr"] = BaseController.Pagecurr;

            return PartialView("Paging");
        }
        public void ReturnViewData_RuongMuoiNha(string ruongmuoi_paging, string nguoilam_paging, string noinhap_paging)
        {
            ViewData["IdForm"] = 6;
            ViewData["ListRuongMuoiNha"] = getListRuongMuoiNha(ruongmuoi_paging, nguoilam_paging, noinhap_paging);
            ViewData["PageCurr"] = BaseController.Pagecurr;
            ViewData["LimitPage"] = BaseController.LimitPage;
            if (totalRow % LimitPage == 0)
            {
                ViewData["TotalPage"] = totalRow / LimitPage;
            }
            else
            {
                ViewData["TotalPage"] = totalRow / LimitPage + 1;
            }
            ViewData["DataRuongMuoiNha"] = null;
        }
        public static List<Data.DBOES.RuongMuoiNha> bindComboxSearch_RuongMuoiNha(string fielName)
        {
            List<Data.DBOES.RuongMuoiNha> objListAll = new List<Data.DBOES.RuongMuoiNha>();
            List<Data.DBOES.RuongMuoiNha> objList = Data.Controllers.RuongMuoiNhaController.RuongMuoiNha_Select_Distinct("RuongMuoiNha_Select_Distinct", fielName);
            Data.DBOES.RuongMuoiNha obj = new Data.DBOES.RuongMuoiNha();
            obj.AnChia = null;
            obj.DienGiai = null;
            obj.DonGia = null;
            obj.GhiChu = null;
            obj.IsActive = null;
            obj.NgayThang = null;
            obj.NguoiLam = null;
            obj.NoiNhap = null;
            obj.RuongMuoi = null;
            obj.SoLuong = null;
            obj.SoXe = null;


            objListAll.Add(obj);
            for (int i = 0; i < objList.Count; i++)
            {
                objList[i].DienGiai = HttpUtility.HtmlDecode(objList[i].DienGiai);
                objList[i].DienGiai = HttpUtility.HtmlDecode(objList[i].DienGiai);
                objList[i].GhiChu = HttpUtility.HtmlDecode(objList[i].GhiChu);
                objList[i].NguoiLam = HttpUtility.HtmlDecode(objList[i].NguoiLam);
                objList[i].NoiNhap = HttpUtility.HtmlDecode(objList[i].NoiNhap);
                objList[i].RuongMuoi = HttpUtility.HtmlDecode(objList[i].RuongMuoi);
                objListAll.Add(objList[i]);
            }
            return objListAll;
        }
    }
}
